﻿using Talented.Core.Entities.Talents.Stats.Abstract;

namespace Talented.Core.Entities.Talents.Stats
{
	public class Stat : StatBase
	{
		public byte Level { get; set; }

		public Stat(StatEnum type, PropertyEnum properties) 
			: base(type, properties)
		{

		}

		public Stat(StatEnum type, PropertyEnum properties, byte position, double initialValue, double[] upgradeSequence, double upgradeFactor) 
			: base(type, properties, position, initialValue, upgradeSequence, upgradeFactor)
		{

		}

		public override StatResult Upgrade()
		{
			return new StatResult
			{
				Position = Position,
				Type = Type,
				Value = CalculateValue()
			};
		}

		private double CalculateValue()
		{
			return 
				Properties.HasFlag(PropertyEnum.NotUpgradeable) 
				? InitialValue 
				: InitialValue * (UpgradeSequence.Length >= Level && UpgradeSequence[Level] > 0 ? UpgradeSequence[Level] : UpgradeFactor * Level);
		}
	}
}
